<?php

namespace app\command;

use app\model\SysMenu;
use support\utils\Time;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;


class InitMenu extends Command
{
    protected static $defaultName = 'init:menu';
    protected static $defaultDescription = 'init:menu';

    /**
     * @return void
     */
    protected function configure()
    {
        $this->addArgument('pid', InputArgument::OPTIONAL, 'pid :pid=0时表示菜单', 0);
        $this->addArgument('name', InputArgument::OPTIONAL, '', "新菜单");
        $this->addArgument('mode', InputArgument::OPTIONAL, 'the menu mode: menu or btn', 'menu');
    }

    /**
     * @param InputInterface $input
     * @param OutputInterface $output
     * @return int
     */
    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $pid = $this->getDefinition()->getArgument("pid");
        $mode = $this->getDefinition()->getArgument("mode");
        $name = $this->getDefinition()->getArgument("name");
        if ($mode == "menu"){
            SysMenu::insert([
                "menuName"=>$name,
                "parentId"=>$pid,
                "menuType"=>"2",
                "isHide"=>0,
                "isKeepAlive"=>0,
                "isFull"=>1,
                "isAffix"=>1,
                "createBy"=>1,
                "createTime"=>Time::now(),
                "updateBy"=>1,
                "updateTime"=>Time::now(),
                "isSpread"=>1,
            ]);
        }else{
            $btn = ['list', 'add', 'update', 'delete'];
            $btnText = ['list'=>"列表", 'add'=>"添加", 'update'=>"修改", 'delete'=>"删除"];
            $insert=[];
            foreach ($btn as $value) {
                $insert[]=[
                    "menuName"=>$btnText[$value]??"",
                    "parentId"=>$pid,
                    "menuType"=>"3",
                    "isHide"=>0,
                    "isKeepAlive"=>0,
                    "isFull"=>1,
                    "isAffix"=>1,
                    "createBy"=>1,
                    "createTime"=>Time::now(),
                    "updateBy"=>1,
                    "updateTime"=>Time::now(),
                    "isSpread"=>1,
                ];
            }
            SysMenu::insertAll($insert);
        }


        return self::SUCCESS;
    }

}
